PROJECT(COINCbc)
################################################################################
#
#  COIN_Cbc: Automated script to generate Solutions for COIN_Cbc
#
################################################################################

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
SET(CBC_ROOT_DIR ${CBC_ROOT_DIR} CACHE PATH "Coin-Cbc Root Directory")
MARK_AS_ADVANCED(CBC_ROOT_DIR)
#At this time, we make a check if the directory is valid. TMC.h is supposed to
#be there in the directory
SET(CBC_IDENTITY_FILE ${CBC_ROOT_DIR}/Cbc/src/CbcConfig.h)

#------------------------------------------------------------------------------#
#Everything will be done only if this file is found
#------------------------------------------------------------------------------#
IF(EXISTS ${CBC_IDENTITY_FILE})
  #-----------------------------------------------------------------------------
  #Common Defines and Include folders
  #-----------------------------------------------------------------------------
  INCLUDE(${PROJECT_SOURCE_DIR}/CMake/Cbc_Includes.cmake)
  INCLUDE(${PROJECT_SOURCE_DIR}/CMake/Cbc_Defines.cmake)
  #-----------------------------------------------------------------------------
  #Define the libraries that are built here
  #-----------------------------------------------------------------------------
  SET(CBC_LIBRARIES
      COIN_Cbc
      COIN_CbcSolver
      COIN_Clp
      COIN_OsiClp
      COIN_Cgl
      COIN_CoinUtils
      COIN_Osi
      COIN_OsiCbc
  )
  #-----------------------------------------------------------------------------
  #Add the required sub-directories
  #-----------------------------------------------------------------------------
  ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/CoinUtils)
  ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/Osi)
  ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/Clp)
  ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/Cgl)
  ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/Cbc)
  #-----------------------------------------------------------------------------
  #All examples that need to be built
  #-----------------------------------------------------------------------------
  SET(BUILD_EXAMPLES OFF CACHE BOOL "Build CBC Examples")
  IF(BUILD_EXAMPLES)
    ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/examples)
  ENDIF()
  
  #-----------------------------------------------------------------------------
  #Executable (Cbc)
  #-----------------------------------------------------------------------------
  ADD_EXECUTABLE(Cbc ${CBC_ROOT_DIR}/Cbc/src/CoinSolve.cpp)
  TARGET_LINK_LIBRARIES(Cbc 
                        COIN_CbcSolver 
                        COIN_Cbc 
                        COIN_Cgl 
                        COIN_OsiClp 
                        COIN_Osi 
                        COIN_Clp 
                        COIN_CoinUtils)
                        
  #All header files (files ending with .hpp)
  FILE(GLOB_RECURSE COINCbc_LIBRARY_HEADER_FILES
       ${CBC_ROOT_DIR}/*.hpp
       ${CBC_ROOT_DIR}/*.h)
  # FILE(GLOB_RECURSE COINCbc_LIBRARY_HEADER_FILES_EXCLUDE
       # ${CBC_ROOT_DIR}/config*.h)
  # FOREACH(B_SRC ${COINCbc_LIBRARY_HEADER_FILES_EXCLUDE})
    #Remove CbcGeneric files
    # LIST(REMOVE_ITEM COINCbc_LIBRARY_HEADER_FILES "${B_SRC}")
  # ENDFOREACH(B_SRC ${COIN_CBC_EXAMPLE_SRCS_NR})

  INSTALL(
    FILES
      ${COINCbc_LIBRARY_HEADER_FILES}
    DESTINATION
      include/coin
  )

  #All executables
  INSTALL(
    TARGETS
      Cbc
    DESTINATION
      bin
  )

  #Install the sample files as well
  FILE(GLOB COINCbc_DATA_FILES
       ${CBC_ROOT_DIR}/Data/Sample/*.mps
	   ${CBC_ROOT_DIR}/Data/Sample/*.stoch
	   ${CBC_ROOT_DIR}/Data/Sample/*.cor
	   ${CBC_ROOT_DIR}/Data/Sample/*.130
	   ${CBC_ROOT_DIR}/Data/Sample/*.time
  )
  
  #All data samples
  INSTALL(
    FILES
      ${COINCbc_DATA_FILES}
    DESTINATION
      CbcData
  )

  #-------------------------------------------------------------------------------
  # Help other projects use COINCbc.
  # SET(LIBRARY_OUTPUT_PATH ${CMAKE_INSTALL_PREFIX}/lib CACHE PATH "Single output directory for building all libraries." FORCE)
  # SET(COINCbc_LIBRARY_PATH ${LIBRARY_OUTPUT_PATH})
  # Save library dependencies.
  EXPORT_LIBRARY_DEPENDENCIES(${CMAKE_INSTALL_PREFIX}/cmake/COINCbcLibraryDepends.cmake)

  # Create the list of include directories needed for LIBXML header files.
  INCLUDE(${PROJECT_SOURCE_DIR}/COINCbcIncludeDirectories.cmake)
  # Create the libCOINCbcConfig.cmake file containing the COINCbc configuration.
  INCLUDE (${PROJECT_SOURCE_DIR}/GenerateCOINCbcConfig.cmake)
  #-------------------------------------------------------------------------------
  # Configure files with settings for use by the build.
  # Copy the UseCOINCbc.cmake file to the binary tree for backward compatability.
  CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/UseCOINCbc.cmake.in
                 ${CMAKE_INSTALL_PREFIX}/cmake/UseCOINCbc.cmake COPYONLY IMMEDIATE)



  #-------------------------------------------------------------------------------
  # Add compiler flags COINCbc needs to work on this platform.  This must be
  # done AFTER the call to CMAKE_EXPORT_BUILD_SETTINGS.

  SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COINCbc_REQUIRED_C_FLAGS}")
  SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COINCbc_REQUIRED_CXX_FLAGS}")
  SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${COINCbc_REQUIRED_LINK_FLAGS}")
  SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${COINCbc_REQUIRED_LINK_FLAGS}")
  SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${COINCbc_REQUIRED_LINK_FLAGS}")
  #-----------------------------------------------------------------------------
  #Installation routines
  #-----------------------------------------------------------------------------
  #ADD_SUBDIRECTORY(${PROJECT_SOURCE_DIR}/Install)
ELSE(EXISTS ${CBC_IDENTITY_FILE})
  MESSAGE("Cannot Build Coin-Cbc without Coin-Cbc Root Directory. Please Set it")
ENDIF(EXISTS ${CBC_IDENTITY_FILE})
